let util = require('../../../../../common/util/util')

Page({
    data: {
        use: []
    },

    onShow: function (options) {
        this.xInit()
    },

    xInit: function () {
        let that = this
        let _dataObj = {
            is_complete: false // false:未完成，true:已完成
        }
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "get_interview_list",
                dataObj: _dataObj
            }
        }).then(res => {
            console.log("返回数据:", res)
            let data = res.result
            for (var i in data) {
                data[i].one_job_management.begin_time = util.formatDate_chinese(new Date(data[i].one_job_management.begin_time))
            }
            console.log(data)
            that.setData({
                use: data
            })
        })
    },

    xOpenPhone: function (e) {
        let phone = e.currentTarget.dataset.phone
        wx.showActionSheet({
            itemList: [phone],
            success: function (res) {
                wx.makePhoneCall({
                    phoneNumber: phone,
                    success: function () {
                        console.log("拨打电话成功！")
                    },
                    fail: function () {
                        console.log("拨打电话失败！")
                    }
                })
                if (!res.cancel) {
                    console.log(res.tapIndex)
                }
            }
        });
    },

    xWrite : function (e) {
        let params = e.currentTarget.dataset
        console.log(params)
        wx.navigateTo({
            url: '/subdter/pages/mine/rec/detail/index?id=' + params.id + '&type=' + params.type,
        })
    },

    xToDet : function (e) {
        let params = e.currentTarget.dataset
        console.log(params)
        wx.navigateTo({
            url: '/subdter/pages/mine/rec/detail/index',
            success: (res) => {
                res.eventChannel.emit('xToDetail', params)
            }
        })
    },

    xOpenVideo: function (e) {
        let params = e.currentTarget.dataset
        console.log(params)
        wx.navigateTo({
            url: '/subdter/pages/mine/rec/video/index?id=' + params.id
        })
    }
})